package com.sgb.zhaocai.view.demand.adapter;

import android.content.Context;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.zhaocai.BR;
import com.sgb.zhaocai.R;
import com.sgb.zhaocai.entity.DemandForecastListEntity;
import com.sgb.zhaocai.entity.GoodsListDTO;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * Time:2021/8/16
 * AUTHOR:F_Q
 * Description:
 */
public class DemandListAdapter extends BaseRecycleAdapter<DemandForecastListEntity> {

    private DemandListTwoAdapter demandlisttwoadapter;

    public DemandListAdapter(Context context, List<DemandForecastListEntity> datas) {
        super(context, R.layout.zc_demand_list, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, DemandForecastListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        //item里面的数据列表
        recyclerviewData(holder, entity);
    }

    private void recyclerviewData(ItemViewHolder holder, DemandForecastListEntity entity) {
        RecyclerView recyclerview = holder.itemView.findViewById(R.id.recyclerview);
        List<List<GoodsListDTO>> goodsList = entity.getGoodsList();
        if (entity.getGoodsHeader() == null || entity.getGoodsList() == null) {
            recyclerview.setVisibility(View.GONE);
        } else {
            recyclerview.setVisibility(View.VISIBLE);
            int count = goodsList.get(0).size();
            recyclerview.setLayoutManager(new GridLayoutManager(context, count));
            demandlisttwoadapter = new DemandListTwoAdapter(context, entity);
            recyclerview.setAdapter(demandlisttwoadapter);
            demandlisttwoadapter.setOnItemClick(new AdapterOnItemClick<GoodsListDTO>() {
                @Override
                public void onItemClick(GoodsListDTO goodsListDTO, int position) {
                    OnItemStateOperate.OnItem(entity);
                }
            });
        }
    }
    private OnItemStateOperate OnItemStateOperate;

    public void setOnItemStateOperate(OnItemStateOperate onItemStateOperate) {
        OnItemStateOperate = onItemStateOperate;
    }

    public interface OnItemStateOperate {
        void OnItem(DemandForecastListEntity entity);
    }

}
